#!/bin/sh

. /opt/truecl/etc/clenv.sh

user=${1:-root}
h=`hostname`

r=`clreq -a echo 2>&1 | 
	perl -ne 'chomp; ($a,$b)=(/^(.+?):(.*)/);
		if($b ne "Alive!") {
			printf("No cluster request daemon running on \"%s\".\n",$a);
		}'`

if [ -n "$r" ]
then
	if [ -x "/usr/bin/mailx" ]
	then
		echo "$r" | /usr/bin/mailx -s "Cluster request daemons down" $user
		exit 0
	fi
	if [ -x "/usr/bin/mail" ]
	then
		echo "Subject: Cluster request daemons down\n$r" | 
			/usr/bin/mail $user
	fi
fi

exit 0
